﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.lib.net
{
   public class Message
    {
        //消息头 125 byte 消息长度 4字节 byte[]数组 int  消息号: byte 1字节   消息体 字节数组  1,4,1

       public byte _id = 0;

       public byte[] _content = null;

       public Message(byte id, byte[] content)
       {
           _id = id;
           _content = content;
       }

       public Message()
       {
 
       }

       /// <summary>
       /// 拼接字节数组
       /// </summary>
       /// <returns></returns>
       public byte[] ToBytes()
       {
           //1+4+1
           byte [] array = new byte[6+_content.Length];
           array[0] = 125;
           array[1] = _id;
           byte[] len = BitConverter.GetBytes(array.Length);
           for (int i = 2; i < 6; i++)
           {
               array[i] = len[i-2];
           }
           Array.Copy(_content, 0, array, 6,_content.Length);
           return array;
       }

    }
}
